package com.liuxinlong.modules.system.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.liuxinlong.modules.common.controller.request.QueryBaseReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.system.controller.request.UpdateRoleRightReq;
import com.liuxinlong.modules.system.service.RoleRightService;

/**
 * 用户权限管理控制层
 * 
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2021-12-31
 */
@RestController
@RequestMapping("/right")
public class RightController {
	@Autowired
	private RoleRightService roleRightService;

	/**
	 * 查询用户权限分页列表
	 *
	 * @param req 查询请求信息
	 * @return 用户权限分页列表
	 */
	@PostMapping("page")
	@LogAnnotation(value ="分页查询",business = LogBusinessConstants.RIGHT_MANAGE,operateType = LogOperateConstants.OPERATE_QUERY)
	public BaseResp pageUserRight(@RequestBody QueryBaseReq req) {
		BaseResp resp = new BaseResp();
		return resp;
	}

	/**
	 * 查询用户角色权限信息
	 * 
	 * @param req 请求信息
	 * @return 用户角色权限信息列表
	 */
	@PostMapping("query")
	@LogAnnotation(value ="查询用户角色权限",business = LogBusinessConstants.RIGHT_MANAGE,operateType = LogOperateConstants.OPERATE_QUERY)
	public BaseResp queryRoleRight(@RequestBody QueryBaseReq req) {
		List<String> dataList = roleRightService.queryRoleRight(req.getId());
		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("data", dataList);
		BaseResp resp = new BaseResp();
		resp.setRetMessage("查询用户角色权限信息成功");
		resp.setDataMap(resultMap);
		return resp;
	}

	/**
	 * 修改用户角色权限
	 *
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("update")
	@LogAnnotation(value ="修改用户角色权限",business = LogBusinessConstants.RIGHT_MANAGE,operateType = LogOperateConstants.OPERATE_MODIFY)
	public BaseResp updateRoleRight(@RequestBody UpdateRoleRightReq req) {
		roleRightService.updateRoleRight(req.getRoleId(), req.getRightList());
		BaseResp resp = new BaseResp();
		resp.setRetMessage("修改用户角色权限成功");
		return resp;
	}
}
